package factory;

public enum FactoryType {

    BMW(0,TypeConstant.TYPE_BMW,BmwCar::new),
    Benz(1,TypeConstant.TYPE_BENZ,BenzCar::new),
    Audi(2,TypeConstant.TYPE_AUDI,AudiCar::new);

    private int index;

    private String type;

    private FactoryFunction factoryFunction;

    public FactoryFunction getFactoryFunction() {
        return factoryFunction;
    }
    FactoryType(int index, String type, FactoryFunction factoryFunction) {
        this.index = index;
        this.type = type;
        this.factoryFunction = factoryFunction;
    }

    public static FactoryType fromType(String type){
        switch (type){
            case TypeConstant.TYPE_BMW:
                return BMW;
            case TypeConstant.TYPE_BENZ:
                return Benz;
            case TypeConstant.TYPE_AUDI:
                return Audi;
        }
        throw new IllegalArgumentException("没有合适的汽车类型");
    }

}
